const webpack = require("webpack"),
  path = require("path"), //node核心模块
  HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
  mode: "production", // development|production
  entry: {
    // 入口配置
    index: ["webpack-dev-server/client?http://localhost:8080/", "src/main.js"]
  },
  output: {
    // 输出配置
    filename: "index.js", // 打包输出文件名
    path: path.resolve(__dirname, "./dist/") // 打包输出路径（必须绝对路径，否则报错）
  },
  devtool,
  module: {
    // 放置loader加载器，webpack本身只能打包commonjs规范的js文件
    rules: [
/*       {
        //规则1
        test: /\.js$/, //js规则
        exclude: /(node_modules)/, //排除modules目录,默认
        use: [
          {
            //使用babel作为js的loade
            loader: "babel-loader",
            options: {
              presets: ["@babel/preset-env"],
              plugins: ["@babel/transform-runtime"]
            }
          }
        ]
      },
      {
        test: /\.css$/,
        use: [
          {
            loader: "style-loader",
            options: {
              insertAt: "top"
            }
          },
          {
            loader: "css-loader"
          }
        ],
        exclude: /node_modules/,
        include: path.resolve(__dirname, "src")
      },
      {
        test: /\.html$/,
        use: [
          {
            loader: "html-loader",
            options: {
              attrs: ["img:src"]
            }
          }
        ]
      },
      {
        test: /\.(png|jpg|jpeg|gif)$/,
        use: [
          {
            loader: "url-loader",
            options: {
              name: "[name]-[hash:5].min.[ext]",
              limit: 10000, // size <= 10KB
              publicPath: "img/",
              outputPath: "img/"
            }
          }
        ]
      } */
    ]
  },
  optimization: {
    // 自定义配置
    minimize: false //不压缩
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: "index.html",
      template: "./src/index.html",
      chunks: ["index"], // entry中的app入口才会被打包
      minify: {
        // 压缩选项
        collapseWhitespace: true
      }
    })
  ], // 插件，扩展功能
  resolve: {
    // 配置模块如何解析
    extensions: [
      ".js",
      ".jsx",
      ".ts",
      ".tsx",
      ".scss",
      ".json",
      ".css",
      ".html"
    ] // 配置之后可以省略上面那些.js .html扩展名
  },
  devServer: {} // webpack-dev-server
};
